<?php

require_once 'BluesCoders/Loader/ILoader.php';

/**
 * Standart class loader
 *
 * @author miho
 */
class BluesCoders_Loader_Standart implements BluesCoders_Loader_ILoader{

    protected $_path;

    public function setPath($value) {
        $this->_path = $value;
        return $this;
    }

    public function getPath() {
        return $this->_path;
    }

    /**
     *
     * @param string $class
     * @return BluesCoders_Loader_ILoader
     */
    public function load($class) {
        $path = $this->_findClassPath($class);

        if(! file_exists($path)) {
            require_once 'BluesCoders/Loader/Exception.php';
            throw new BluesCoders_Loader_Exception(sprintf('Path %s does not exists', $path));
        }

        include_once $path;

        if(! class_exists($class)) {
            require_once 'BluesCoders/Loader/Exception.php';
            throw new BluesCoders_Loader_Exception(sprintf('Class %s does not found in %s', $class, $path));
        }

        return $this;
    }

    protected function _findClassPath($class) {
        return $this->_path .DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR, $class).'.php';
    }

}
?>
